let liftCycle=[
    'beforeCreate','created','beforeMount','mounted','beforeUpdate','updated','destoryed','beforeDestory',
]
let stract={}
liftCycle.forEach(life=>{
    stract[life]=mergeHook
})
stract.components=function(opt1,opt2){
    let res=Object.create(opt1)
    if(opt2){
        for(let key in opt2){
            res[key]=opt2[key]
        }
    }
    return res
}
function mergeHook(lif1,lif2){
    if(lif2){
        if(lif1){
            return [lif1,lif2]
        }else{
            return lif2
        }
    }else{
        return lif1
    }
}
export function mergeOptions(opt1,opt2){
    let options={}
    for(let key in opt1){
       mergeField(key)
    }
    for(let key in opt2){
        if(!options.hasOwnProperty(key)){
            mergeField(key)
        }
    }
    function mergeField(key){
        if(stract[key]){
            //生命周期混入
            return options[key]=stract[key](opt1[key],opt2[key])
            
        }
        if(typeof opt1[key]==='object'&&typeof opt2[key] ==='object'){
            options[key]={
                ...opt1[key],
                ...opt2[key]
            }
        }else if(!opt2[key]){

            options[key]=opt1[key]
        }else{
            options[key]=opt2[key]
        }
    }
    return options
}

